module.exports = function ($scope, $state, $resource, $modal, $stateParams, toaster ){
    

    //查询已发消息列表
    $scope.search = function (pageNo){
        console.log($stateParams.Collname)
        var para = {
            'pageNo': pageNo || $scope.currentPage,
            'pageSize': $scope.itemsPerPage,
            'Collname' : $stateParams.Collname,
            'type': '1'
        }
        $resource('/api/ac/sc/informaticaService/findInfomatica', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                $scope.list = res.data.results;
                $scope.totalItems = res.data.totalRecord;
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }

    init();
    //初始化列表
    function init(){
        $scope.currentPage = 1;		//当前页码
        $scope.itemsPerPage = 10;	//每页显示几条
        $scope.search(1);
    }

    //添加or修改
    $scope.save = function(info) {
        info.openstate = false;
        info.seeopenstate = true;
       console.log(111);
        var modalInstance = $modal.open({
            template: require('../views/saveinformatica.html'),
            controller: 'saveinformatica',
            size: 'lg',
            resolve: {
                item : function () {
                    return info;
                },
                flag : function () {
                    return info == 1;
                }
            }
        });
        //关闭模态框刷新页面
        modalInstance.result.then(function() {
            init();
        });
    }

    //发送
    $scope.send = function(info) {
        var para = {
            'id' : info._id
                 }
         $resource('/api/ac/sc/informaticaService/insertsendInformatica', {}, {}).save(para, function(res){
             if(res.errcode === 0){
                toaster.success({title: '', body: '发送成功'});
                init();
             }else{
                 toaster.error({title: '', body: res.errmsg});
             }
         });
    }


        //查看
        $scope.gatLawInfo = function(info) {
            var para = {
                'id' : info._id
                     }
             $resource('/api/ac/sc/informaticaService/updategetInfomatica', {}, {}).save(para, function(res){
                 if(res.errcode === 0){
                     info = res.data;
                 }else{
                     toaster.error({title: '', body: res.errmsg});
                 }
             });
             
            info.openstate = true;
            info.seeopenstate = false;
            var modalInstance = $modal.open({
                template: require('../views/saveinformatica.html'),
                controller: 'saveinformatica',
                size: 'lg',
                resolve: {
                    item : function () {
                        return info;
                    },
                    flag : function () {
                        return info == 1;
                    }
                }
            });
            //关闭模态框刷新页面
            modalInstance.result.then(function() {
                init();
            });
        }

   
   

};